<?php
/**[规则控制器]
 * @Author: chenli
 * @Email:  976123967@qq.com
 * @Date:   2015-02-23 11:53:41
 * @Last Modified by:   chenli
 * @Last Modified time: 2015-02-24 14:35:06
 */
class AuthRuleAction extends PublicAction{
	public $logic;
	public function _initialize()
	{
		parent::_initialize();
		$this->logic = D('AuthRule','Logic');
	}
	/**
	 * [index 规则列表]
	 * @return [type] [description]
	 */
	public function index()
	{
		$data = $this->logic->find_all();
		$this->assign('data',$data);

		$this->display();
	}

	/**
	 * [add 添加]
	 */
	public function add()
	{

		if(IS_POST)
		{
			if(!$this->logic->add_auth_rule())
				$this->error($this->logic->getError());

			$this->success('规则添加成功',U('AuthRule/index'));
			die;
		}


		$data = $this->logic->find_all();
		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		$this->logic->update_cache();
		$this->success('更新缓存成功',U('AuthRule/index'));
	}

	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{
		if(IS_POST)
		{
			if(!$this->logic->edit_auth_rule())
				$this->error($this->logic->getError());
			$this->success('规则编辑成功',U('AuthRule/index'));
			die;
		}


		$data = $this->logic->find_all();
		$this->assign('data',$data);

		$field = $this->logic->find_one();
		if(!$field)
			$this->error($this->logic->getError());
		$this->assign('field',$field);


		$this->display();

	}

	/**
	 * [del 删除规则]
	 * @return [type] [description]
	 */
	public function del()
	{
		if(!$this->logic->del_auth_rule())
			$this->error($this->logic->getError());
		$this->success('规则删除成功',U("AuthRule/index"));
	}

	// 执行批量处理操作
	public function operation()
	{
		if(!$msg = $this->logic->operation())
			$this->error($this->logic->getError());
		$this->success($msg,U('AuthRule/index'));
	}



}